import axios from 'axios'
import store from '@/store'
import qs from 'qs'

// axios.defaults.baseURL = "http://161.117.83.241:5003/api/v2/crm/"
// axios.defaults.headers.common['Authorization'] = AUTH_TOKEN

// const baseURL = "http://161.117.83.241:5003/api/v2/crm/"
const baseURL = 'https://hq.nngcloud.com.cn/userSystem/api/v2/crm/'
// 添加请求拦截器
axios.interceptors.request.use(function(config){
    //发送请求前
    
    let token = store.state.userInfo.token
    
    if(token){
        config.headers['Authorization']= "bearer " + token;
    }
    return config;
},function(error){
    return Promise.reject(error)
})


// 密码登录
export const login = params => {
    return axios.post(`${baseURL}user/login`, params).then(res => res.data)
}

// 发送验证码
export const sendCodeRequest = params => {
    return axios.post(`${baseURL}user/sendCode`, params)
    .then(res => res.data)
}

// 手机验证码登录
export const codeLogin = params => {
    return axios.post(`${baseURL}user/loginByPhone`, params)
    .then(res => res.data)
}

// 注册
export const register = params => {
    return axios.post(`${baseURL}user/registerByPhone`, params)
    .then(res => res.data)
}

// 忘记密码
export const forgetPwd = params => {
    return axios.post(`${baseURL}user/forgetPwd`, params)
    .then(res => res.data)
}

// 忘记密码中的确认验证码
export const commitCode = params => {
    return axios.post(`${baseURL}user/commitCode`, params)
    .then(res => res.data)
}

// 快速登录
export const quickLogin = params => {
    return axios.post(`${baseURL}user/quickLogin`, params)
    .then(res => res.data)
}

// 获取区号列表
export const areaList = () => {
    return axios.post(`${baseURL}user/sendAreaCode`)
    .then(res => res.data)
}

// 获取用户列表
export const userList = params => {
    return axios.post(`${baseURL}user/list`, params)
    .then(res => res.data)
}

// 获取用户头像
export const userAvatar = params => {
    return axios.post(`${baseURL}user/avatar`, params)
    .then(res => res.data)
}

// 获取用户信息
export const getUserInfo = params => {
    return axios.post(`${baseURL}user/profile`, params)
    .then(res => res.data)
}